package com.parse.core;

import android.app.Activity;
import android.widget.Toast;

import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
import com.parse.api.SigningService;
import com.parse.bean.SignDTO;

public class SignServiceImpl implements SigningService {

	@Override
	public void signin(SignDTO dto, final Activity activity) {
		ParseUser user = new ParseUser();

		user.setUsername(dto.getUserId());
		user.setPassword(dto.getPassword());
		user.setEmail(dto.getEmail());
		user.put("phone", dto.getPhone());

		user.signUpInBackground(new SignUpCallback() {
			public void done(ParseException e) {

				if (e == null) {
					Toast.makeText(activity, "註冊成功", Toast.LENGTH_SHORT).show();

					activity.setResult(Activity.RESULT_OK);
					activity.finish();
					// Hooray! Let them use the app now.
				} else {
					
					
					
					
					Toast.makeText(activity, "帳號已存在", Toast.LENGTH_SHORT)
							.show();
					// Sign up didn't succeed. Look at the ParseException
					// to figure out what went wrong
				}
			}
		});

	}

}
